<template>
    <div class="goods-list">
        <div class="goods-type" v-for="item in goodslist" :key="item.id" @click='jumpluyou(item.id)'>
            <div class="goods-show">
                <img :src="item.img_url">
                <p>{{item.title}}</p>
            </div>
            <div class="goods-info">
                <p class="goods-price">
                    <span class="now-price">￥{{ item.sell_price }}</span>
                    <span class="old-price">￥{{item.market_price}}</span>
                </p>
                <p class="goods-sell">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>
        <!-- 加载更多 -->
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>


<script>
    export default {
        data() {
            return {
                goodspage: 1,
                goodslist: []
            }
        },
        created() {
            this.getgoodslist();
        },
        methods: {
            getgoodslist() {
                this.$http.get("api/getgoods?pageindex=" + this.goodspage).then(result => {
                    if (result.body.status === 0) {
                        // console.log(result.body.message);
                        this.goodslist = this.goodslist.concat(result.body.message);
                    }
                })
            },
            getMore() {
                this.goodspage++;
                this.getgoodslist();
            },
            jumpluyou(ids) {
                //this.$route对象是路由参数对象，所有路由参数：query，params都属于它
                //this.$router对象是路由导航对象，它能够方便的使用js代码，进行路由的前进，后退跳转到新的url地址
                this.$router.push({name: 'goodsinfo', params: {id: ids}})
            }
        }
    }
</script>


<style lang="scss" scoped>
    .goods-list {
        display: flex;
        flex-wrap: wrap; //必要时让div拆行
        padding: 7px;
        justify-content: space-between;
        .goods-type {
            width: 49%;
            background-color: white;
            box-shadow: 0 0 9px #ccc;
            border: 1px solid #ccc;
            margin: 4px 0;
            padding: 3px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 293px;
            .goods-show {
                img {
                    width: 100%;
                }
            }
            .goods-info {
                background-color: #eee;
                margin: 0;
                padding: 5px;
                .goods-price {
                    .now-price {
                        color: red;
                        font-weight: bold;
                        font-size: 16px;
                    }
                    .old-price {
                        text-decoration: line-through;
                        font-size: 12px;
                        margin: 10px;
                    }
                }
                .goods-sell {
                    display: flex;
                    justify-content: space-between;
                }
            }
        }
    }
</style>